package com.study.demo.demo;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;

@Slf4j
public class AbortPolicyDemo {

    public static void main(String[] args) throws Exception{

        int corePoolSize = 5;
        int maximumPoolSize = 10;
        long keepAliveTime = 5;

        BlockingQueue<Runnable> workQueue = new LinkedBlockingDeque<>(10);
        RejectedExecutionHandler handler = new ThreadPoolExecutor.DiscardOldestPolicy();

        ThreadPoolExecutor executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, TimeUnit.SECONDS, workQueue, handler);

        for (int i = 0;i<100;i++){

            try{
                executor.execute(new Thread(()->log.info(Thread.currentThread().getName() + " is running")));
            }catch (Exception e){
                e.printStackTrace();
            }
        }


        executor.shutdown();
    }
}
